{include file="common/head"/}
<div class="main-container" id="main-container">
    <script type="text/javascript">
        try{ace.settings.check('main-container' , 'fixed')}catch(e){}
    </script>
    {include file="common/left"}
    <div class="main-content">
        <div class="main-content-inner">
            {include file="common/header_nav"}
            <div class="page-content">
                <div class="row maintop">
                    <div class="col-xs-12 col-sm-2">
                        <!-- 点击模态框（Modal） -->
                        <button class="btn btn-xs btn-danger" data-toggle="modal" data-target="#myModal">
                            <i class="ace-icon fa fa-plus bigger-110"></i>
                            添加广告
                        </button>
                    </div>
                    <form name="admin_list_sea" class="form-search" method="post" action="{:url('adList')}">
                        <div class="col-xs-12 col-sm-6 btn-sespan">
                            <div class="input-group">
                                <span class="input-group-addon">
                                    <i class="ace-icon fa  fa-search"></i>
                                </span>
                                <input type="text" name="key" id="key" class="form-control search-query admin_sea" value="{$testkey}" placeholder="输入广告名称" />
                                <span class="input-group-btn">
                                    <button type="submit" class="btn btn-xs btm-input btn-purple">
                                        搜索
                                    </button>
                                </span>
                            </div>
                        </div>
                    </form>
                    <div class="input-group-btn">
                        <a href="{:url('adList')}">
                            <button type="button" class="btn btn-xs all-btn btn-purple">
                                <span class="ace-icon fa fa-globe icon-on-right bigger-110"></span>
                                显示全部
                            </button>
                        </a>
                    </div>
                </div>
                <div class="row">
                    <div class="col-xs-12">
                        <form id="plug_ad_allorder" name="plug_ad_allorder" method="post" action="{:url('adOrder')}" >
                            <div class="table-responsive">
                                <table id="dynamic-table" class="table table-striped table-bordered table-hover center">
                                    <thead>
                                    <tr>
                                        <th class="center wh90">ID</th>
                                        <th class="center">广告名称</th>
                                        <th class="center">所属位置</th>
                                        <th class="center">添加时间</th>
                                        <th class="center">排序</th>
                                        <th class="center">状态</th>
                                        <th class="center" style="border-right:#CCC solid 1px;width: 120px;">操作</th>
                                    </tr>
                                    </thead>

                                    <tbody>
                                    {volist name="adList" id="v"}
                                    <tr>
                                        <td>{$v.ad_id}</td>
                                        <td class="text-left"><a href="{$v.url}" target="_blank">{$v.name}{if condition="$v.pic"}<img src="__STATIC__/img/admin_image.gif">{/if}</a></td>
                                        <td>{$v.typename}</td>
                                        <td>{$v.addtime|date='Y-m-d',###}</td>
                                        <td><input name="{$v.ad_id}" value="{$v.sort}" class="list_order"/></td>
                                        <td>
                                            {if condition='$v["open"] eq 1'}
                                            <a class="red" href="javascript:;" onclick="return stateyes({$v.ad_id});" title="已开启">
                                                <div id="zt{$v.ad_id}"><button class="btn btn-minier btn-yellow">状态开启</button></div>
                                            </a>
                                            {else/}
                                            <a class="red" href="javascript:;" onclick="return stateyes({$v.ad_id});" title="已禁用">
                                                <div id="zt{$v.ad_id}"><button class="btn btn-minier btn-danger">状态禁用</button></div>
                                            </a>
                                            {/if}
                                        </td>
                                        <td>
                                            <div class="action-buttons">
                                                <a class="green"  href="{:url('adEdit',array('ad_id'=>$v['ad_id']))}" title="修改">
                                                    <i class="ace-icon fa fa-pencil bigger-130"></i>
                                                </a>
                                                <a class="red" href="javascript:;" onclick="return del({$v.ad_id});" title="删除">
                                                    <i class="ace-icon fa fa-trash-o bigger-130"></i>
                                                </a>
                                            </div>
                                        </td>
                                    </tr>
                                    {/volist}
                                    <tr>
                                    <tr>
                                        <td align="left"><button type="submit"  id="btnorder" class="btn btn-white btn-yellow btn-sm">排序</button></td>
                                        <td colspan="6" align="right">{$page}</td>
                                    </tr>
                                    </tbody>
                                </table>
                            </div>
                        </form>
                    </div><!-- /.col -->
                </div><!-- /.row -->
            </div><!-- /.page-content -->
        </div>
    </div><!-- /.main-content -->
    {include file="common/foot" /}
</div>
<!-- 显示模态框（Modal） -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <form class="form-horizontal" name="adInsert" id="adInsert" method="post" action="{:url('adInsert')}">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                    <h4 class="modal-title" id="myModalLabel">添加广告</h4>
                </div>
                <div class="modal-body">
                    <div class="row">
                        <div class="col-xs-12">
                            <div class="form-group">
                                <label class="col-sm-2 control-label no-padding-right" for="type_id"> 所属位置： </label>
                                <div class="col-sm-10">
                                    <select name="type_id" id="type_id" class="col-sm-4 selector" >
                                        <option value="">请选择所属广告位</option>
                                        {foreach name="adTypeList" item="v"}
                                        <option value="{$v.type_id}">{$v.name}</option>
                                        {/foreach}
                                    </select>
                                </div>
                            </div>
                            <div class="space-4"></div>
                            <div class="form-group">
                                <label class="col-sm-2 control-label no-padding-right" for="name"> 广告名称：  </label>
                                <div class="col-sm-10">
                                    <input type="text" name="name" id="name" placeholder="输入广告名称" class="col-xs-10 col-sm-5" />
                                </div>
                            </div>
                            <div class="space-4"></div>
                            <div class="form-group">
                                <label class="col-sm-2 control-label no-padding-right">广告图片：  </label>
                                <div class="col-sm-10">
                                    <div class="thumb_box" id="thumb_box">
                                        <div id="thumb_aid_box"></div>
                                        <a href="javascript:swfupload('thumb_uploadfile','thumb','文件上传',1,1,1,'jpeg,jpg,png,gif',3,2,yesdo,nodo)">
                                            <img src="__STATIC__/img/admin_upload_thumb.png" id="thumb_pic">
                                        </a><br>
                                        <input type="button" value="取消缩略图" onclick="javascript:clean_thumb('thumb');" class="btn btn-success btn-sm" style="margin-top: 5px;">
                                        <input type="hidden" id="thumb" name="checkpic" value="">
                                    </div>
                                </div>
                            </div>
                            <div class="form-group" id="pic_listurl">
                                <label class="col-sm-2 control-label no-padding-right" for="url"> 链接URL：  </label>
                                <div class="col-sm-10">
                                    <input type="text" name="url" id="url" placeholder="输入链接URL" class="col-xs-10 col-sm-8" />
                                    <span class="lbl">&nbsp;&nbsp;<span class="red">*</span>必须是以http://开头</span>
                                </div>
                            </div>
                            <div class="space-4"></div>

                            <div class="form-group">
                                <label class="col-sm-2 control-label no-padding-right" for="open"> 是否审核： </label>
                                <div class="col-sm-10" style="padding-top:5px;">
                                    <input name="open" id="open" value="1" class="ace ace-switch ace-switch-4 btn-flat" type="checkbox" />
                                    <span class="lbl">&nbsp;&nbsp;默认关闭</span>
                                </div>
                            </div>
                            <div class="space-4"></div>

                            <div class="form-group">
                                <label class="col-sm-2 control-label no-padding-right" for="sort"> 排序：  </label>
                                <div class="col-sm-10">
                                    <input type="text" name="sort" id="sort" value="50" class="col-xs-10 col-sm-3" />
                                    <span class="lbl">&nbsp;&nbsp;<span class="red">*</span>从小到大排序</span>
                                </div>
                            </div>
                            <div class="space-4"></div>
                        </div>
                    </div>
                </div>
                <div class="modal-footer">
                    <button type="submit" class="btn btn-primary">
                        提交保存
                    </button>
                    <button class="btn btn-info" type="reset">
                        重置
                    </button>
                    <button type="button" class="btn btn-default" data-dismiss="modal">
                        关闭
                    </button>
                </div>
            </div>
        </div>
    </form>
</div>
<script>
    function del(id){
        layer.confirm('你确定要删除吗？', {icon: 3}, function(index){
            layer.close(index);
            window.location.href="{:url('adDel')}?ad_id="+id;
        });
    }

    function stateyes(val){
        $.post('{:url("adState")}', {id:val}, function(data){
            if(data.status){
                if(data.info=='状态禁止'){
                    var a='<button class="btn btn-minier btn-danger">状态禁用</button>'
                    $('#zt'+val).html(a);
                    return false;
                }else{
                    var b='<button class="btn btn-minier btn-yellow">状态开启</button>'
                    $('#zt'+val).html(b);
                    return false;
                }
            }
        });
        return false;
    }

    //添加操作
    $(function(){
        $('#adInsert').ajaxForm({
            beforeSubmit: checkForm, // 此方法主要是提交前执行的方法，根据需要设置
            success: complete, // 这是提交后的方法
            dataType: 'json'
        });

        function checkForm(){
            if( '' == $(".selector").val()){
                layer.alert('所属广告位不能为空', {icon: 5}, function(index){
                    layer.close(index);
                    $('.selector').focus();
                });
                return false;
            }

            if( '' == $.trim($('#name').val())){
                layer.alert('广告名称不能为空', {icon: 5}, function(index){
                    layer.close(index);
                    $('#name').focus();
                });
                return false;
            }
        }
        function complete(data){
            if(data.status==1){
                layer.alert(data.info, {icon: 6}, function(index){
                    layer.close(index);
                    window.location.href=data.url;
                });
            }else{
                layer.alert(data.info, {icon: 5}, function(index){
                    layer.close(index);
                    window.location.href=data.url;
                });
                return false;
            }
        }
    });

    //批量排序
    $(function(){
        $('#plug_ad_allorder').ajaxForm({
            success: complete, // 这是提交后的方法
            dataType: 'json'
        });
        function complete(data){
            if(data.status==1){
                layer.alert(data.info, {icon: 6}, function(index){
                    layer.close(index);
                    window.location.href=data.url;
                });
            }else{
                layer.alert(data.info, {icon: 6}, function(index){
                    layer.close(index);
                    window.location.href=data.url;
                });
            }
        }
    });
</script>
</body>
</html>
